package com.sxmmall.ware.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.sxmmall.ware.entity.vo.MergeVo;
import com.sxmmall.ware.entity.vo.PurchaseDoneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.sxmmall.ware.entity.PurchaseEntity;
import com.sxmmall.ware.service.PurchaseService;
import com.sxmmall.common.utils.PageUtils;
import com.sxmmall.common.utils.R;


/**
 * 采购信息
 *
 * @author sxm
 * @email 1125400943@qq.com
 * @date 2021-07-07 14:44:49
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("ware:purchase:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }

    /*
     * @Author sxm
     * @Description 未领取的采购订单
     * @Date 23:59 2021/9/22
     * @Param [params]
     * @return [java.util.Map<java.lang.String,java.lang.Object>]
     **/
    @RequestMapping("/unreceive/list")
    public R unReceiveList(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseService.queryPageUnReceivePurchase(params);
        return R.ok().put("page", page);
    }


    /*
     * @Author sxm
     * @Description 合并采购需求
     * @Date 0:08 2021/9/23
     * @Param [mergeVo]
     * @return [com.sxmmall.ware.entity.vo.MergeVo]
     **/
    @PostMapping("/merge")
    public R merge(@RequestBody MergeVo mergeVo) {
        purchaseService.mergePurchase(mergeVo);
        return R.ok();
    }

    /*
     * @Author sxm
     * @Description 领取采购单
     * @Date 11:14 2021/9/23
     * @Param [ids]
     * @return [com.sxmmall.ware.entity.vo.MergeVo]
     **/
    @PostMapping("/received")
    public R receivedPurchase(@RequestBody List<Long> ids) {
        purchaseService.receivedPurchase(ids);
        return R.ok();
    }

    /*
     * @Author sxm
     * @Description 完成采购订单
     * @Date 12:18 2021/9/23
     * @Param [purchaseDoneVo]
     * @return [com.sxmmall.ware.entity.vo.PurchaseDoneVo]
     **/
    @PostMapping("/done")
    public R done(@RequestBody PurchaseDoneVo purchaseDoneVo){
        purchaseService.done(purchaseDoneVo);
        return R.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("ware:purchase:info")
    public R info(@PathVariable("id") Long id) {
        PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("ware:purchase:save")
    public R save(@RequestBody PurchaseEntity purchase) {
        purchase.setCreateTime(new Date());
        purchase.setUpdateTime(new Date());
        purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("ware:purchase:update")
    public R update(@RequestBody PurchaseEntity purchase) {
        purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //  @RequiresPermissions("ware:purchase:delete")
    public R delete(@RequestBody Long[] ids) {
        purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
